//
//  HZMallSqlDataManager.m
//  app
//
//  Created by 刘华舟 on 15/5/13.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZMallSqlDataManager.h"

#import "HZOrderByerAddressModel.h"
#import "HZGoodsDetailVCData.h"
#import "HZCartCellModel.h"

#import "SNBaseInfoManager.h"

#import "JSONKit.h"

static NSString *const kMallNSDataIntervalFormmat = @"kMallNSDataIntervalFormmat";


@interface HZMallSqlDataManager()

@property (strong, nonatomic) SNFmdbManager *handler;

@end

@implementation HZMallSqlDataManager

+ (instancetype)defaultManager{
    static HZMallSqlDataManager *_SQLiteManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _SQLiteManager = [[self alloc] initManager];
    });
    return _SQLiteManager;
}

- (instancetype)initManager{
    if (self = [super init]) {
        self.handler = [SNFmdbManager shareManager];
        
        // 1.创建地址缓存表
        NSString *createTableSQL = @"create table if not exists t_user_address(id integer primary key autoincrement, nation text, province text, city text, district text, address text, postcode text, phone text, receiver text, selected text, fullAddress text, timestamp text);";
        [self createTable:@"t_user_address" withSQL:createTableSQL];
        
        // 2.创建热门搜索缓存表
        createTableSQL = @"create table if not exists t_mall_hot_search(id integer primary key autoincrement, result blob, timestamp text);";
        [self createTable:@"t_mall_hot_search" withSQL:createTableSQL];
        
        // 3.创建商品分类缓存表
        createTableSQL = @"create table if not exists t_mall_find_categories(id integer primary key autoincrement, result blob, timestamp text, url text);";
        [self createTable:@"t_mall_find_categories" withSQL:createTableSQL];
        
        // 4.创建购物车商品选择态缓存表
        createTableSQL = @"create table if not exists t_mall_product_chose_status(id integer primary key autoincrement, productid text);";
        [self createTable:@"t_mall_product_chose_status" withSQL:createTableSQL];
        
        // 5.创建搜索历史缓存表
        createTableSQL = @"create table if not exists t_mall_search_history(id integer primary key autoincrement, keyword text);";
        [self createTable:@"t_mall_search_history" withSQL:createTableSQL];
        
//        // 6.创建商品列表
//        createTableSQL = @"create table if not exists t_mall_goods(shop_id text, product_id primary key text, product_title text, pic text, width text, height text, tag_price text, sale_price text, shop_name text, buy_num text, act_id text, reserve_num text, gift text, product_type text, start_time text, end_time text);";
//        [self createTable:@"t_mall_goods" withSQL:createTableSQL];
        
        // 6.商品购物车的列表
        createTableSQL = @"create table if not exists t_mall_carts(product_id text primary key, buy_num text, result blob);";
        [self createTable:@"t_mall_carts" withSQL:createTableSQL];
    }
    return self;
}

- (void)createTable:(NSString *)tableName withSQL:(NSString *)sql{
    
    if (![self.handler fmdbIncludetableWithTableName:tableName]) {
        [self.handler createTableWithSql:sql];
    }
    
}

//--------------------------------------------------------------------------------------------
//用户地址缓存方法
//--------------------------------------------------------------------------------------------

//添加一个默认地址
- (BOOL)addNewUserDefaultAddressWithModel:(HZOrderByerAddressModel *)model temptime:(NSString *)time{
    
    if (model.isDefaultAddress) {
        [self updateAllUserAddressUnDefault];
    }
    
    if (time == nil) {
        time = [self queryForAddressCacheDataTemptime];
        if (time == nil) {
            time = [NSString stringWithFormat:@"%f", [NSDate date].timeIntervalSince1970];
        }
    }
    
    NSString *sql = @"insert into t_user_address(id, nation, province, city, district, address, postcode, phone, receiver, selected, fullAddress, timestamp) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    NSString *fullAddress = [NSString stringWithFormat:@"%@%@%@%@",model.nation,model.city,model.district,model.address];
    NSArray *arguments = @[model.addressID, model.nation, model.province, model.city, model.district, model.address, model.postcode, model.phone, model.receiver, [NSString stringWithFormat:@"%d", model.isDefaultAddress], fullAddress, time];
    
    return [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
}

//插入一个默认地址
- (BOOL)insertNewUserDefaultAddressWithModel:(HZOrderByerAddressModel *)model temptime:(NSString *)time{
    
    if (time == nil) {
        time = [self queryForAddressCacheDataTemptime];
        if (time == nil) {
            time = [NSString stringWithFormat:@"%f", [NSDate date].timeIntervalSince1970];
        }
    }
    
    
    NSString *sql = @"insert into t_user_address(id, nation, province, city, district, address, postcode, phone, receiver, selected, fullAddress, timestamp) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    NSArray *arguments = @[model.addressID, model.nation, model.province, model.city, model.district, model.address, model.postcode, model.phone, model.receiver, [NSString stringWithFormat:@"%d", model.isDefaultAddress], model.fullAddress, time];
    
    return [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
}

//删除所有地址的缓存
- (BOOL)deleteAllAddressCacheData{
    NSString *sql = [NSString stringWithFormat:@"delete from t_user_address"];
    
    return [self.handler performExecuteUpdateWithSql:sql];
}
//删除某个地址缓存
- (BOOL)deleteUserAddressWithModel:(HZOrderByerAddressModel *)model{
     NSString *sql = [NSString stringWithFormat:@"delete from t_user_address where id='%@'", model.addressID];
    
    return [self.handler performExecuteUpdateWithSql:sql];
}


//更新某用户地址列表缓存
- (void)updateUserDefaultAddressWithModel:(HZOrderByerAddressModel *)model temptime:(NSString *)time{
    
    if (model.isDefaultAddress) {
        [self updateAllUserAddressUnDefault];
    }
    
    [self deleteUserAddressWithModel:model];
    
    [self addNewUserDefaultAddressWithModel:model temptime:time];
}
//更新某用户全部地址列表缓存
- (void)updateUserAllAddressWithModel:(NSArray *)addressList temptime:(NSString *)time{
    
    [self deleteAllAddressCacheData];
    
    for (HZOrderByerAddressModel *model in addressList) {
        [self insertNewUserDefaultAddressWithModel:model temptime:time];
    }
}

//设置全部地址为非默认
- (void)updateAllUserAddressUnDefault{
    NSString *sql = @"update t_user_address set selected='0'";
    [self.handler performExecuteUpdateWithSql:sql];
}

//查询地址时间搓
- (NSString *)queryForAddressCacheDataTemptime{
     NSString *sql = @"select timestamp from t_user_address";
    
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    if ([resultSet hasNext]) {
        return [resultSet stringForColumn:@"timestamp"];
    }else{
        return @"0";
    }
}

//查询用户所有地址
- (NSArray *)queryForAllUserAddress{
    
    NSString *sql = @"select * from t_user_address";
    
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    NSMutableArray *array = [NSMutableArray array];
    while([resultSet hasNext]) {
        NSDictionary *dict = @{APIKEY_mall_id:[resultSet stringForColumn:APIKEY_mall_id],
                               APIKEY_mall_nation:[resultSet stringForColumn:APIKEY_mall_nation],
                               APIKEY_mall_province:[resultSet stringForColumn:APIKEY_mall_province],
                               APIKEY_mall_city:[resultSet stringForColumn:APIKEY_mall_city],
                               APIKEY_mall_district:[resultSet stringForColumn:APIKEY_mall_district],
                               APIKEY_mall_address:[resultSet stringForColumn:APIKEY_mall_address],
                               APIKEY_mall_postcode:[resultSet stringForColumn:APIKEY_mall_postcode],
                               APIKEY_mall_phone:[resultSet stringForColumn:APIKEY_mall_phone],
                               APIKEY_mall_receiver:[resultSet stringForColumn:APIKEY_mall_receiver],
                               APIKEY_mall_selected:[resultSet stringForColumn:APIKEY_mall_selected],
                               APIKEY_mall_fullAddress:[resultSet stringForColumn:APIKEY_mall_fullAddress]};
        
        if ([[resultSet stringForColumn:APIKEY_mall_selected] isEqualToString:@"1"]) {
            [array insertObject:dict atIndex:0];
        }else{
            [array addObject:dict];
        }
    }
    return [NSArray arrayWithArray:array];
}


//--------------------------------------------------------------------------------------------
//商品分类缓存方法
//--------------------------------------------------------------------------------------------

//更新商品分类缓存
- (void)updateFindCategoriesWithData:(NSDictionary *)dict{
    NSMutableData *data = [[NSMutableData alloc] init];
    //NSDictionary字典转NSData
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:dict forKey:kMallNSDataIntervalFormmat];
    [archiver finishEncoding];
    
    if ([self deleteFindCategoriesData]) {
        [self insertFindCategoriesWithhData:data];
    }
}
//插入商品分类新数据
- (BOOL)insertFindCategoriesWithhData:(NSData *)data{
    
    NSString *sql = @"insert into t_mall_find_categories(result, timestamp, url) values (?, ?, ?)";
    NSTimeInterval nowSrvTime = [NSDate date].timeIntervalSince1970-[[[SNBaseInfoManager shareManager] baseInfoObjectForKey:kHZTimeOffsetBetweenServerAndLocal] floatValue];
    NSArray *arguments = @[data, [NSString stringWithFormat:@"%f", nowSrvTime], [SNUniteUrl shareUniteUrl].static_catogarypageUrl];
    return [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
}

//删除商品分类的缓存
- (BOOL)deleteFindCategoriesData{
    
    NSString *sql = [NSString stringWithFormat:@"delete from t_mall_find_categories"];
    
    return [self.handler performExecuteUpdateWithSql:sql];
}

//查询商品分类时间戳
- (NSString *)queryFindCategoriesTimeStamp{
    NSString *sql = [NSString stringWithFormat:@"select * from t_mall_find_categories"];
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    if ([resultSet hasNext]) {
        NSString *timestamp = [resultSet stringForColumn:@"timestamp"];
        if (timestamp && timestamp.length>0) {
            return timestamp;
        }else{
            return @"0";
        }
    }
    return @"0";
}

//查询商品分类URL
- (NSString *)queryFindCategoriesURL{
    NSString *sql = [NSString stringWithFormat:@"select * from t_mall_find_categories"];
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    if ([resultSet hasNext]) {
        NSString *timestamp = [resultSet stringForColumn:@"url"];
        if (timestamp && timestamp.length>0) {
            return timestamp;
        }else{
            return @"";
        }
    }
    return @"";
}

//查询商品分类缓存
- (NSDictionary *)loadFindCategoriesData{
    NSString *sql = [NSString stringWithFormat:@"select * from t_mall_find_categories"];
    
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    if ([resultSet hasNext]) {
        NSData *data = [resultSet dataForColumn:@"result"];
        if (data) {
            NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
            NSDictionary *dict = [unarchiver decodeObjectForKey:kMallNSDataIntervalFormmat];
            [unarchiver finishDecoding];
            return dict;
        }else{
            return [NSDictionary dictionary];
        }
    }
    
    return [NSDictionary dictionary];
//    //取本地文件
//    NSString *jsonDataPath = [[NSBundle mainBundle] pathForResource:kMallFileLocalFindCategoriesJsonData ofType:@"json"];
//    
//    NSError *error;
//    NSString *jsonDataStr = [NSString stringWithContentsOfFile:jsonDataPath encoding:NSUTF8StringEncoding error:&error];
//    
//    NSDictionary *jsonData = [jsonDataStr objectFromJSONString];
//    
//    
//    return [jsonData objectForKey:APIKEY_mall_result];
}


//--------------------------------------------------------------------------------------------
//热搜词汇缓存方法
//--------------------------------------------------------------------------------------------

//更新热搜词汇缓存
- (void)updateHotKeyWordsCacheWithData:(NSDictionary *)dict{
    NSMutableData *data = [[NSMutableData alloc] init];
    //NSDictionary字典转NSData
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:dict forKey:kMallNSDataIntervalFormmat];
    [archiver finishEncoding];
    
    if ([self deleteHotKeywordsData]) {
        [self insertHotKeywordsWithhData:data];
    }
}
//插入某标签帖子列表新数据
- (BOOL)insertHotKeywordsWithhData:(NSData *)data{
    
    NSString *sql = @"insert into t_mall_hot_search(result, timestamp) values (?, ?)";
    NSTimeInterval nowSrvTime = [NSDate date].timeIntervalSince1970-[[[SNBaseInfoManager shareManager] baseInfoObjectForKey:kHZTimeOffsetBetweenServerAndLocal] floatValue];
    NSArray *arguments = @[data, [NSString stringWithFormat:@"%f", nowSrvTime]];
    return [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
}

//删除热搜词汇的缓存
- (BOOL)deleteHotKeywordsData{
    
    NSString *sql = [NSString stringWithFormat:@"delete from t_mall_hot_search"];
    
    return [self.handler performExecuteUpdateWithSql:sql];
}

//查询热搜词汇时间戳
- (NSString *)queryHotKeywordsTimeStamp{
    NSString *sql = [NSString stringWithFormat:@"select * from t_mall_hot_search"];
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    if ([resultSet hasNext]) {
        NSString *timestamp = [resultSet stringForColumn:@"timestamp"];
        if (timestamp && timestamp.length>0) {
            return timestamp;
        }else{
            return @"0";
        }
    }
    return @"0";
}

//查询热搜词汇缓存
- (NSDictionary *)loadHotKeywordsData{
    NSString *sql = [NSString stringWithFormat:@"select * from t_mall_hot_search"];
    
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    if ([resultSet hasNext]) {
        NSData *data = [resultSet dataForColumn:@"result"];
        if (data) {
            NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
            NSDictionary *dict = [unarchiver decodeObjectForKey:kMallNSDataIntervalFormmat];
            [unarchiver finishDecoding];
            return dict;
        }else{
            return [NSDictionary dictionary];
        }
    }
    return [NSDictionary dictionary];
}



//--------------------------------------------------------------------------------------------
//搜索记录缓存方法
//--------------------------------------------------------------------------------------------

//更新所有历史搜索缓存
- (void)updateMallSearchHistoryCacheWithData:(NSString *)keyword
{
    NSString *sql = @"select * from t_mall_search_history";
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    
    if (resultSet.rowCount >= 50) {
        sql = @"delete from t_mall_search_history where min(id)";
        [self.handler performExecuteUpdateWithSql:sql];
    }
    
    sql = @"insert into t_mall_search_history(keyword) values (?)";
    NSArray *arguments = @[keyword];
    [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
    
}
//查询所有历史搜索
- (NSArray *)queryAllMallSearchHistory
{
    NSString *sql = @"select distinct keyword from t_mall_search_history order by id desc";
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    NSMutableArray *array = [NSMutableArray array];
    while([resultSet hasNext]) {
        NSString *keyword = [resultSet stringForColumn:@"keyword"];
        if (keyword) {
            [array addObject:keyword];
        }else{
            return array;
        }
    }
    return array;
}

//删除所有历史搜索的缓存
- (BOOL)deleteAllSearchHistoryCacheData{
    NSString *sql = @"delete from t_mall_search_history";
    return [self.handler performExecuteUpdateWithSql:sql];
}


//--------------------------------------------------------------------------------------------
//记录购物车商品的选择态缓存方法
//--------------------------------------------------------------------------------------------

//更新某个商品的选择态缓存 有则删除 无则插入
- (void)updateProductChoseStatuWithProductID:(NSString *)productID selected:(BOOL)isSelected{
    if (isSelected) {
        if (![self queryProductChoseStatuWithProductID:productID]) {
            NSString *sql = @"insert into t_mall_product_chose_status(productid) values (?)";
            NSArray *arguments = @[productID];
            [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
            
        }
    }else{
        NSString *sql = @"delete from t_mall_product_chose_status where productid=?";
        NSArray *arguments = @[productID];
        [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
    }
    
}
//删除所有商品选择态的缓存
- (BOOL)deleteAllProductChoseStatus{
    NSString *sql = @"delete from t_mall_search_history";
    return [self.handler performExecuteUpdateWithSql:sql];
}
//查询某个商品的选择态
- (BOOL)queryProductChoseStatuWithProductID:(NSString *)prductID{
    NSString *sql = [NSString stringWithFormat:@"select * from t_mall_product_chose_status where productid='%@'", prductID];
    SNResultSet *resultSet = [self.handler performExecuteQueryWithSql:sql];
    
    if (resultSet.hasNext) {
        return YES;
    }
    
    return NO;
}




//--------------------------------------------------------------------------------------------
//购物车离线数据
//--------------------------------------------------------------------------------------------
//查询所有的购物车离线数据
- (NSArray *)queryAllOfflineMallCartsCacheData
{
    NSMutableArray *list = [NSMutableArray array];
    [self.handler.fmdbQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        NSString *sql = @"select * from t_mall_carts";
        
        
        FMResultSet * rs = [db executeQuery:sql];
        
        while ([rs next]) {
            NSMutableDictionary *product = [NSMutableDictionary dictionaryWithDictionary:[[rs stringForColumn:@"result"] objectFromJSONString]];
            [product setObject:[rs stringForColumn:@"product_id"] forKey:@"product_id"];
            [product setObject:[rs stringForColumn:@"buy_num"] forKey:@"buy_num"];
           
            [list addObject:product];
        }
        
        [rs close];
        
    }];
    
    
    return list;
}

//查询某种商品在购物车内的数量
- (NSInteger)queryProductNumInCartsCacheDataWithProductID:(NSString *)productID
{
    NSString *sql = @"select * from t_mall_carts where product_id=?";
    NSArray *arguments = [NSArray arrayWithObject:productID];
    SNResultSet *productSet = [self.handler performExecuteQueryWithSql:sql withArguments:arguments];
    
    if ([productSet hasNext]) {
        return [[productSet stringForColumn:@"buy_num"] integerValue];
    }
    
    return 0;
}

//更新某个商品的购买数量 (购物车)
- (BOOL)updateOfflineCartsCacheDataWithModel:(HZCartCellModel *)model{
    /** 记录用户共买了多少个该商品 -write by khzliu */
    NSString *buyNum = model.goodsCountNum;
    
    
    
    NSString *sql = @"update t_mall_carts where buy_num=?, where product_id=?";
    
    
    NSArray *arguments = [NSArray arrayWithObjects:buyNum, model.goodsID, nil];
    
    return [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
}

//插入一个新的购物车的离线数据 (商品详情)
- (BOOL)insertOfflineCartsCacheDataWithModel:(HZGoodsDetailVCData *)data
{
    /** 记录用户共买了多少个该商品 -write by khzliu */
    NSString *buyNum = [NSString stringWithFormat:@"%d", data.headModel.topModel.buyNum];
    /** 添加数据库中已有的数量 -write by khzliu */
    buyNum = [NSString stringWithFormat:@"%d", [self queryProductNumInCartsCacheDataWithProductID:data.headModel.topModel.productID]+[buyNum integerValue]];
    
    /** 生成改商品的json字符串 -write by khzliu */
    NSMutableDictionary *product = [NSMutableDictionary dictionary];
    
     HZGoodsDetailTopModel *topModel = data.headModel.topModel;
    
    /** 封装该商品的其他属性值 -write by khzliu */
    [product setObject:topModel.shopID forKey:APIKEY_mall_shop_id];
    [product setObject:topModel.productTitle forKey:APIKEY_mall_product_title];
    /** pic 为该商品的图片 -write by khzliu */
    NSDictionary *picDict = [topModel.productPictures firstObject];
    NSString *pic = @"";
    if (picDict.count) {
        pic = [picDict stringForKey:APIKEY_mall_pic nilValue:@""];
    }
    [product setObject:pic  forKey:APIKEY_mall_pic];
    [product setObject:topModel.width forKey:APIKEY_mall_width];
    [product setObject:topModel.height forKey:APIKEY_mall_height];
    [product setObject:topModel.tagPrice forKey:APIKEY_mall_tag_price];
    [product setObject:topModel.salePrice forKey:APIKEY_mall_sale_price];
    [product setObject:topModel.shopName forKey:APIKEY_mall_shop_name];
    
    /** actID 为该商品参加的所有活动的ID，如果该商品没有活动，那么它的活动ID为0 -write by khzliu */
    NSString *actID = @"0";
    if (data.headModel.promotion.count > 0) {
        NSMutableArray *promotionIDArray = [NSMutableArray array];
        for (NSDictionary *item in data.headModel.promotion) {
            [promotionIDArray addObject:[item stringForKey:APIKEY_mall_id nilValue:@""]];
        }
        
        actID = [NSString stringWithFormat:@"%@", [promotionIDArray componentsJoinedByString:@","]];
    }
    [product setObject:actID forKey:APIKEY_mall_act_id];
    [product setObject:topModel.num forKey:@"reserveNum"];
    [product setObject:topModel.productType forKey:APIKEY_mall_product_type];
    [product setObject:topModel.srvStartTime forKey:@"start_time"];
    [product setObject:topModel.srvEndTime forKey:@"end_time"];
    
    /** gift 为该商品增送的全部赠品列表ID 如果没有赠品那么改值就为空 -write by khzliu */

    NSMutableArray *giftList = [NSMutableArray array];
    for (HZGoodsCuXiaoCellViewModel *giftModel in data.headModel.promotionModel.topCellArray) {
        NSString *selected = @"0";
        
        if (giftModel.selected) {
            selected = @"1";
        }
        
        [giftList addObject:@{APIKEY_mall_title:giftModel.title,
                              APIKEY_mall_product_id:giftModel.productID,
                              APIKEY_mall_selected:selected,
                              APIKEY_mall_pic:giftModel.url,
                              }];
    }
    
    NSDictionary *gift = @{APIKEY_mall_maxgift:@"1",
                           APIKEY_mall_list:giftList};
    [product setObject:gift forKey:APIKEY_mall_gift];
       
    


    NSString *sql = @"replace into t_mall_carts(product_id, buy_num, result) VALUES (?, ?, ?)";
    
    /** 转换商品字典为字符串 -write by khzliu */
    NSString *result = [product JSONString];
    
    
    NSArray *arguments = [NSArray arrayWithObjects:topModel.productID, buyNum, result, nil];
    
    return [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
    
}
//删除所有购物车的离线数据
- (BOOL)deleteOfflineCartsCacheDataWithProductID:(NSString *)productID{
    NSString *sql = @"delete from t_mall_carts where product_id=?";
    
    NSArray *arguments = [NSArray arrayWithObjects:productID, nil];
    
    return [self.handler performExecuteUpdateWithSql:sql withArguments:arguments];
}
//删除所有购物车的离线数据
- (BOOL)deleteAllOfflineCartsCacheData
{
    
    NSString *sql = @"delete from t_mall_carts";

    return [self.handler performExecuteUpdateWithSql:sql];
}


@end
